home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 076-100 / disk_096 / animplayer / saveanim.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  3KB  |  149 lines

  1. /***************************************************************************
  2.  *
  3.  *   NAME 
  4.  *      SaveANIM -- save an IFF ANIM file to disk
  5.  *
  6.  *   SYNOPSIS
  7.  *      if (SaveANIM( directory, frame, bitmapold, bitmapnew, viewport ))
  8.  * 
  9.  *      char directory[];
  10.  *      UWORD frame;
  11.  *      struct BitMap *bitmapold,
  12.  *              *bitmapnew;
  13.  *      struct ViewPort *viewport;
  14.  *
  15.  *   DESCRIPTION
  16.  *      As the animation continues, each frame is saved to disk
  17.  *      under a subdirectory created with the name of the choreography,
  18.  *      and each file name is the number of the frame.
  19.  *
  20.  *      copyright (c) 1987 Martin D. Hash
  21.  *
  22.  *   LAST EDITED
  23.  *      Martin Hash            22 Aug 1987
  24.  *
  25.  *   EDIT HISTORY
  26.  *       5 Aug  MH  Created.
  27.  *
  28.  **********************************************************************/
  29.  
  30. #include <exec/types.h>
  31. #include <intuition/intuition.h>
  32. #include <libraries/dos.h>
  33. #include <libraries/dosextens.h>
  34. #include <df1:ilbm.h>
  35. #include "df1:FileCons.h"
  36. #include "df1:ANIMCons.h"
  37.  
  38. /* EXTERNAL FUNCTIONS */
  39.  
  40. struct FileLock *Lock(),
  41.         *CreateDir();
  42. BOOL UserRequest(),
  43.      Pack_Frame();
  44.  
  45. /* FILE VARIABLES */
  46.  
  47. static char text[MAXNUMBERTEXT];
  48.  
  49. static struct IntuiText frametext = {
  50.    2, 0, JAM1,
  51.    0, 0, NULL,
  52.    text,
  53.    NULL
  54. };
  55.  
  56. /* FUNCTION */
  57.  
  58. static BOOL ANHD_Chunk( file, anhd )
  59.  
  60. BPTR file;
  61. ANHD *anhd;
  62. {
  63.    /* LOCAL VARIABLES */
  64.  
  65.    ULONG ANHDsize;
  66.  
  67.    /* CODE */
  68.  
  69.    if (Write( file, "ANHD", 4*sizeof(char)) == -1)
  70.       return FALSE;
  71.    ANHDsize = sizeof(ANHD);
  72.    if (Write( file, &ANHDsize, sizeof(ULONG)) == -1)
  73.       return FALSE;
  74.    if (Write( file, anhd, sizeof(ANHD)) == -1)
  75.       return FALSE;
  76.    return TRUE;
  77. }
  78.  
  79. /* FUNCTION */
  80.  
  81. BOOL SaveANIM( directory, frame, bitmapold, bitmapnew, viewport )
  82.  
  83. char directory[];
  84. UWORD frame;
  85. struct BitMap *bitmapold,
  86.           *bitmapnew;
  87. struct ViewPort *viewport;
  88. {
  89.    /* LOCAL VARIABLES */
  90.  
  91.    BPTR file;
  92.    char name[STRINGSIZE];
  93.    struct FileLock *lock;
  94.    ANHD anhd;
  95.    ULONG zero = 0;
  96.  
  97.    /* FUNCTION */
  98.  
  99.    strcpy( name, "frames:anim" );
  100.    if ((lock = Lock( name, ACCESS_READ )) == 0) 
  101.       if ((lock = CreateDir( name )) == 0) {
  102.          UserRequest( "          CANT CREATE ANIM" );
  103.          return FALSE;
  104.       }
  105.    UnLock( lock );
  106.  
  107.    strcat( name, "/" );
  108.    strcat( name, directory );
  109.  
  110.    if ((lock = Lock( name, ACCESS_READ )) == 0) 
  111.       if ((lock = CreateDir( name )) == 0) {
  112.          UserRequest( "         CANT CREATE FILE" );
  113.          return FALSE;
  114.       }
  115.    UnLock( lock );
  116.  
  117.    stci_d( text, (int)frame, sizeof(text));
  118.    strcat( name, "/" );
  119.    strcat( name, text );
  120.  
  121.    if ((lock = Lock( name, ACCESS_READ )) != 0) {
  122.       file = Open( name, MODE_OLDFILE );
  123.       UnLock( lock );
  124.    }
  125.    else
  126.       file = Open( name, MODE_NEWFILE );
  127.  
  128.    anhd.operation = XORVERT;
  129.    if (frame == 1 || frame == 2) {
  130.       Write( file, "FORM", 4*sizeof(char));
  131.       Write( file, &zero, sizeof(ULONG));
  132.       Write( file, "ANIM", 4*sizeof(char));
  133.       PutPicture( file, bitmapnew, viewport->ColorMap->ColorTable );  
  134.       Write( file, "FORM", 4*sizeof(char));
  135.       Write( file, &zero, sizeof(ULONG));
  136.       Write( file, "ILBM", 4*sizeof(char));
  137.       ANHD_Chunk( &anhd );
  138.    }
  139.    else if (!Pack_Frame( file, bitmapold, bitmapnew, 
  140.        viewport->ColorMap->ColorTable )) {
  141.       Close( file );
  142.       DeleteFile( name );
  143.       return FALSE;
  144.    }      
  145.  
  146.    Close( file );
  147.    return TRUE;
  148. }
  149.